/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package view;

import control.ConsultaTableModel;
import java.util.Date;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.Query;
import javax.persistence.TemporalType;
import model.beans.Consulta;
import model.persistence.GerenciadorEntidades;

/**
 *
 * @author kelyane
 */
public class HomeSecretary extends javax.swing.JFrame {

    /**
     * Creates new form HomeSecretary
     */
    public HomeSecretary() {
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jMenu1 = new javax.swing.JMenu();
        jLabel1 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tableVerConsultasHoje = new javax.swing.JTable();
        jButton1 = new javax.swing.JButton();
        jMenuBar1 = new javax.swing.JMenuBar();
        menuAddPaciente = new javax.swing.JMenu();
        addPaciente = new javax.swing.JMenuItem();
        menuDelUpPaciente = new javax.swing.JMenuItem();
        menuVerPaciente = new javax.swing.JMenuItem();
        jMenu5 = new javax.swing.JMenu();
        menuAddConsulta = new javax.swing.JMenuItem();
        menuDelUpConsulta = new javax.swing.JMenuItem();
        menuVerConsulta = new javax.swing.JMenuItem();
        menuVerConsultaProxDia = new javax.swing.JMenuItem();

        jMenu1.setText("jMenu1");

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Home Secretaria");
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowOpened(java.awt.event.WindowEvent evt) {
                formWindowOpened(evt);
            }
        });

        jLabel1.setText("Consultas do Dia");

        tableVerConsultasHoje.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Data", "Horario", "Medico", "Paciente"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, true, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane1.setViewportView(tableVerConsultasHoje);

        jButton1.setText("Atualizar");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        menuAddPaciente.setText("Paciente");
        menuAddPaciente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuAddPacienteActionPerformed(evt);
            }
        });

        addPaciente.setText("Adicionar");
        addPaciente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addPacienteActionPerformed(evt);
            }
        });
        menuAddPaciente.add(addPaciente);

        menuDelUpPaciente.setText("Editar/Excluir");
        menuDelUpPaciente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuDelUpPacienteActionPerformed(evt);
            }
        });
        menuAddPaciente.add(menuDelUpPaciente);

        menuVerPaciente.setText("Visualizar");
        menuVerPaciente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuVerPacienteActionPerformed(evt);
            }
        });
        menuAddPaciente.add(menuVerPaciente);

        jMenuBar1.add(menuAddPaciente);

        jMenu5.setText("Consulta");

        menuAddConsulta.setText("Adicionar");
        menuAddConsulta.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuAddConsultaActionPerformed(evt);
            }
        });
        jMenu5.add(menuAddConsulta);

        menuDelUpConsulta.setText("Editar/Excluir");
        jMenu5.add(menuDelUpConsulta);

        menuVerConsulta.setText("Ver Consultas");
        menuVerConsulta.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuVerConsultaActionPerformed(evt);
            }
        });
        jMenu5.add(menuVerConsulta);

        menuVerConsultaProxDia.setText("Ver Consultas Próx Dia");
        jMenu5.add(menuVerConsultaProxDia);

        jMenuBar1.add(jMenu5);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 924, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton1)
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(22, 22, 22)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jButton1))
                .addGap(18, 18, 18)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 358, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(52, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    public void preencherTabela() {
        EntityManager em = GerenciadorEntidades.getEntityManager();
        Query query = em.createNamedQuery("findConsultaHorario");
        Date hoje = new Date();
        query.setParameter("horario", hoje, TemporalType.DATE);

        List<Consulta> consultasNamedQuery = query.getResultList();

        ConsultaTableModel tableModel = new ConsultaTableModel();

        for (Consulta consulta : consultasNamedQuery) {

            tableModel.addRow(consulta);

        }
        tableVerConsultasHoje.setModel(tableModel);
    }

    private void formWindowOpened(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowOpened
        preencherTabela();
    }//GEN-LAST:event_formWindowOpened

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        preencherTabela();
    }//GEN-LAST:event_jButton1ActionPerformed

    private void menuAddPacienteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuAddPacienteActionPerformed
    }//GEN-LAST:event_menuAddPacienteActionPerformed

    private void menuDelUpPacienteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuDelUpPacienteActionPerformed
        new UpDelPaciente().setVisible(true);
    }//GEN-LAST:event_menuDelUpPacienteActionPerformed

    private void addPacienteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addPacienteActionPerformed
        new CadastrarPaciente().setVisible(true);
    }//GEN-LAST:event_addPacienteActionPerformed

    private void menuAddConsultaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuAddConsultaActionPerformed
        new CadastrarConsulta().setVisible(true);
    }//GEN-LAST:event_menuAddConsultaActionPerformed

    private void menuVerPacienteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuVerPacienteActionPerformed
        new VerPacientes().setVisible(true);
    }//GEN-LAST:event_menuVerPacienteActionPerformed

    private void menuVerConsultaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuVerConsultaActionPerformed
        new VerConsultas().setVisible(true);
    }//GEN-LAST:event_menuVerConsultaActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(HomeSecretary.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(HomeSecretary.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(HomeSecretary.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(HomeSecretary.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new HomeSecretary().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenuItem addPaciente;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu5;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JMenuItem menuAddConsulta;
    private javax.swing.JMenu menuAddPaciente;
    private javax.swing.JMenuItem menuDelUpConsulta;
    private javax.swing.JMenuItem menuDelUpPaciente;
    private javax.swing.JMenuItem menuVerConsulta;
    private javax.swing.JMenuItem menuVerConsultaProxDia;
    private javax.swing.JMenuItem menuVerPaciente;
    private javax.swing.JTable tableVerConsultasHoje;
    // End of variables declaration//GEN-END:variables
}
